<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="/WEB-INF/tld/c.tld"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">
<%@include file="../common/common_ui.jsp"%>
<title>资源管理</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<style type="text/css">
/* 	自动换行 */
table {word-wrap;break-word;
	word-break: break-all;
}
</style>

</head>
<script type="text/javascript">

//权限详情
function displaySecondLevel(op,id){
	var _this=$(op);
	var isClick=_this.attr("isClick");
	if(isClick=='0'){
		_this.attr("isClick","1");
		var control=$("#tr_detail_"+id);	  
		control.addClass("tr_selected").show();
		$("#resourceDetail_"+id).attr("src","<%=path%>/resourceInfo/querySubResource.do?id="+id);			
	}else{
		_this.attr("isClick","0");
		$(".temp_tr").hide();
		$(".tr_selected").removeClass("tr_selected");	
	}
};

function loadChildPage(iframeId){
	$("#resourceDetail_"+iframeId).attr("src","<%=path%>/resourceInfo/querySubResource.do?id="+iframeId);
}

function addRes(){
	window.parent.sopen("<%=path%>/resourceInfo/toAddResourcePage.do?","新增资源",600,550);
};

function updateRes(id){
	window.parent.sopen("<%=path%>/resourceInfo/toUpdateResourcePage.do?id="+id,"更新权限",600,550);
};

/*
* 作废角色
*/
function deleteRes(id){
	 var message = "确定作废";
	 window.parent.sconfirm(message, function(){
		 $.post("<%=path%>/resourceInfo/deleteResource.do", {
             times:new Date().getTime(),
             id:id
             }, function() {
            	 location.href="<%=path%>/resourceInfo/toResourceInfoPage.do";
     	});
	 });
};
/*
* 重启角色
*/
function restartRes(id){
	 var message = "确定重启";
	 window.parent.sconfirm(message, function(){
		 $.post("<%=path%>/resourceInfo/restartResource.do", {
             times:new Date().getTime(),
             id:id
             }, function() {
            	 location.href="<%=path%>/resourceInfo/toResourceInfoPage.do";
     	});
	 });	 
};

$(document).ready(function(){
	$("#status").val(${status});
	});

</script>


<body>
	<div class="matter">
		<div class="widget">
				<div class="widget-head">
					<div class="pull-left">查询条件1</div>
					<div class="clearfix"></div>
				</div>
				<div class="widget-content">
					<div class="padd">
						<!-- Form starts.  -->
						<form id="frm" name="frm" class="form-horizontal" role="form"
							action="<%=path%>/resourceInfo/queryResourceList.do" method="post">
							<table>
								<tr>
									<td><label>名称:</label>&nbsp;&nbsp;</td>
									<td><input id="name" name="name" type="text"
										class="form-control" value="${param.name}">
									</td>
									
									<td>&nbsp;&nbsp;<label>等级:</label>&nbsp;&nbsp;
									</td>
									
									<td> <select class="form-control" name="level" id="level">
											<option value="">--</option>
											<option value="1" <c:if test = "${param.level eq '1'}">selected</c:if> >一级</option>
											<option value="2" <c:if test = "${param.level eq '2'}">selected</c:if> >二级</option>
									</select>
									</td>
									<td>&nbsp;&nbsp;<label>类型:</label>&nbsp;&nbsp;
									</td>
									<td>
											<select class="form-control" name="type" id="type">
											<option value="">--</option>
											<option value="1" <c:if test = "${param.type eq '1'}">selected</c:if>>菜单</option>
											<option value="2" <c:if test = "${param.type eq '2'}">selected</c:if>>按钮</option>
									</select>
									</td>
									<td>&nbsp;&nbsp;<label>父权限:</label>&nbsp;&nbsp;
									</td>
									<td> <select class="form-control" name="parentId" id="parentId">
											<option value="">--</option>
											<c:forEach var="pi" items="${parentInfo}">
												<option value="${pi.parentId}" <c:if test = "${param.parentId eq pi.parentId}">selected</c:if> >${pi.parentName}</option>
											</c:forEach>
									</select>
									</td>
									<td>
									&nbsp;&nbsp;
									<!-- Split button -->
									<div class="btn-group">
									  <button type="submit" id="search" class="btn btn-primary">查询</button>
									  <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
									    <span class="caret"></span>
									    <span class="sr-only">Toggle Dropdown</span>
									  </button>
									  <ul class="dropdown-menu" role="menu">
									    <li><a href="javascript:$('#status').val(1);document.frm.submit();">查询有效权限</a></li>
									    <li><a href="javascript:$('#status').val(0);document.frm.submit();">查询无效权限</a></li>
									  </ul>
									</div>
									&nbsp;&nbsp;
									<button type="button" style="margin-left:2px" class="btn btn-default" onclick="addRes();">新增</button>
									<!-- 状态1，有效；0，无效 -->
									<input type="hidden" name="status" id="status" value="${status}">
									</td>
								</tr>
							</table>
						</form>
					</div>
				</div>
		</div>
	</div>

	<div class="widget">
		<div class="widget-head">
			<div class="pull-left">查询结果</div>
			<div class="clearfix"></div>
		</div>

		<div class="widget-content">
			<table class="table table-striped table-bordered table-hover" >
				<thead>
					<tr>
					    <th>&nbsp;</th>
						<th>No</th>
						<th>名称</th>
						<th>URL</th>
						<th>备注</th>
						<th>类型</th>
						<th>状态</th>
						<th>操作</th>
					</tr>
				</thead>
				
				<div class="widget-content" name="orgtable" id="orgtable">

				<tbody>
					<c:forEach items="${resourceInfoList}" var="firstlevel" varStatus="instatus">
						<tr>
							<td>
									<button isClick="0" id="displaySecondLevel" onclick="displaySecondLevel(this,'${firstlevel.id}');" class="btn btn-xs btn-default">+</button>
							</td>
							<td>${instatus.count}</td>
							<td>${firstlevel.name}</td>
							<td>${firstlevel.url}</td>
							<td>${firstlevel.memo}</td>
							<c:if test="${firstlevel.type eq '1'}">
								<td>菜单</td>
							</c:if>
							<c:if test="${firstlevel.type eq '2'}">
								<td>按钮</td>
							</c:if>

							<c:if test="${firstlevel.status eq '0'}">
								<td><span class="label label-default">无效</span></td>
							</c:if>
							<c:if test="${firstlevel.status eq '1'}">
								<td><span class="label label-success">有效</span></td>
							</c:if>

							<c:if test="${firstlevel.status eq '1'}">
								<td>
									<button id="update" onclick="updateRes('${firstlevel.id}');"
										class="btn btn-xs btn-info">
										<span class="glyphicon glyphicon-pencil"></span>编辑
									</button>
									<button id="del" onclick="deleteRes('${firstlevel.id}');"
										class="btn btn-xs btn-danger">
										<span class="glyphicon  glyphicon-trash"></span>作废
									</button>
								</td>
							</c:if>

							<c:if test="${firstlevel.status eq '0'}">
								<td>
									<button id="restart"
										onclick="restartRes('${firstlevel.id}');"
										class="btn btn-xs btn-success">
										<span class="glyphicon glyphicon-ok"></span>启用
									</button>
								</td>
							</c:if>
							
						</tr>
							<tr valign="top" class="temp_tr" id="tr_detail_${firstlevel.id}" style="display: none" name="resDet">
						  
						  	<td>&nbsp;</td>
							<td valign="top" colspan="7" style='margin:0px;' >
									 <iframe width="98%" id="resourceDetail_${firstlevel.id}" frameborder="0" height="100px"
						        style="height:300px;"></iframe>	
							</td>
						  </tr>
						 
					</c:forEach>
				</tbody>
				
				</div>
				
			</table>
		</div>
	</div>
</body>
</html>
